﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Main_Reports_Accounts_OutStandings_Paybles : System.Web.UI.Page
{
    Datautility du = new Datautility();
    AccountSettings ac = new AccountSettings();
    double dbltotaloriginal = 0;
    double dbltotalreceived = 0;
    double dbltotalpending = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        if (!IsPostBack)
        {
            lblcompname.Text = Session["compname"].ToString();
            hidFinyear.Value = Session["FinYear"].ToString();
            txtToDate.Text = "31/03/" + (Convert.ToInt32(Session["FinYear"].ToString()) + 1).ToString();

            grid_grdDisplay(txtToDate.Text);
        }

    }
    protected void grid_grdDisplay(string strToDate)
    {
        SqlParameter[] pr = {new  SqlParameter("@GROUPTREEID","001005002"),
                               new SqlParameter("@TODATE",string.Format("{0:MM-dd-yyyy}",Convert.ToDateTime(strToDate)))
                           };
        DataTable dt = du.getdatausingprocedure("USP_ACC_GetOutstandingDetails", pr);
        lblheading.Text = "Outstanding View for selected Ledgers as on " + string.Format("{0:dd-MM-yyyy}", Convert.ToDateTime(strToDate));
        grdDisplay.DataSource = dt;
        grdDisplay.DataBind();

    }

    protected void show(object sender, EventArgs e)
    {
        grid_grdDisplay(txtToDate.Text);
    }
    protected void rowdatabound(object sender, GridViewRowEventArgs e)
    {
        string strTranstyepId = string.Empty;
        string strTransDate = string.Empty;
        string strTransId = string.Empty;
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[5].Text != string.Empty)
            {
                dbltotaloriginal += Math.Abs(Convert.ToDouble(e.Row.Cells[5].Text));

            }
            if (Math.Abs(Convert.ToDouble(e.Row.Cells[5].Text)) == 0)
            {
                e.Row.Cells[5].Text = string.Empty;
            }
            else
            {
                e.Row.Cells[5].Text = ac.GetCurrency(Math.Abs(Convert.ToDouble(e.Row.Cells[5].Text))).ToString();
            }

            if (e.Row.Cells[7].Text != string.Empty)
            {
                dbltotalpending += Math.Abs(Convert.ToDouble(e.Row.Cells[7].Text));

            }
            if (Math.Abs(Convert.ToDouble(e.Row.Cells[7].Text)) == 0)
            {
                e.Row.Cells[7].Text = string.Empty;
            }
            else
            {
                e.Row.Cells[7].Text = ac.GetCurrency(Math.Abs(Convert.ToDouble(e.Row.Cells[7].Text))).ToString();
            }
            if (e.Row.Cells[8].Text != string.Empty)
            {
                dbltotalreceived += Math.Abs(Convert.ToDouble(e.Row.Cells[8].Text));

            }
            if (Math.Abs(Convert.ToDouble(e.Row.Cells[8].Text)) == 0)
            {
                e.Row.Cells[8].Text = string.Empty;
            }
            else
            {
                e.Row.Cells[8].Text = ac.GetCurrency(Math.Abs(Convert.ToDouble(e.Row.Cells[8].Text))).ToString();
            }
            strTranstyepId = grdDisplay.DataKeys[e.Row.RowIndex].Values["TransactionTypeID"].ToString();
            strTransDate = string.Format("{0:MM/dd/yyyy}", grdDisplay.DataKeys[e.Row.RowIndex].Values[1].ToString());      
            strTransId = grdDisplay.DataKeys[e.Row.RowIndex].Values["TransactionID"].ToString();

            SqlParameter[] pr ={ new  SqlParameter("@TYPEID",strTranstyepId)
                           };
            DataTable dt = du.getdatausingprocedure("USP_ACC_GetTransactionsSettings", pr);
            if (dt.Rows[0]["ModuleType"].ToString() == "1")
            {
                string strFromDate = "04/01/" + Session["FinYear"].ToString();
                string strToDate = "03/31/" + (Convert.ToInt32(Session["FinYear"].ToString()) + 1).ToString();
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "2")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "4")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "6")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "7")
                {
                    string url = "";
                }
            }
            if (dt.Rows[0]["ModuleType"].ToString() == "2")
            {
                string strFromDate = "04/01/" + Session["FinYear"].ToString();
                string strToDate = "03/31/" + (Convert.ToInt32(Session["FinYear"].ToString()) + 1).ToString();
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "2")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "4")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "6")
                {
                    string url = "";
                }
                if (dt.Rows[0]["PARENTTYPEID"].ToString() == "7")
                {
                    string url = "";
                }
            }
        }
        



        if (e.Row.RowType == DataControlRowType.Footer)
        {
            e.Row.Cells[4].Text = "Total";
            e.Row.Cells[5].Text = ac.GetCurrency(dbltotaloriginal).ToString();
            e.Row.Cells[7].Text = ac.GetCurrency(dbltotalpending).ToString();
            e.Row.Cells[8].Text = ac.GetCurrency(dbltotalreceived).ToString();
            e.Row.HorizontalAlign = HorizontalAlign.Right;
            e.Row.Font.Bold = true;
        }


    }
    protected void lnkback_Click(object sender, EventArgs e)
    {
        Response.Redirect("outstandings.aspx");
    }
}
